package cn.mengfly.testnrz.util;

import cn.mengfly.testnrz.nio.NioDemoConfig;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;

public class BootStrapUtil {


    public static void initServer(ServerBootstrap b, EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
        b.group(bossGroup, workerGroup);
        b.channel(NioServerSocketChannel.class);
        b.localAddress(NioDemoConfig.SOCKET_PORT);
        b.option(ChannelOption.SO_KEEPALIVE, true);
        b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    }

    public static void initClient(Bootstrap b, EventLoopGroup workerGroup) {
        b.group(workerGroup);
        b.channel(NioSocketChannel.class);
        b.remoteAddress(NioDemoConfig.SOCKET_IP, NioDemoConfig.SOCKET_PORT);
        b.option(ChannelOption.SO_KEEPALIVE, true);
        b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
    }
}
